{extend name="normal_base" /}
{block name="navigation"}{/block}
{block name="body"}
<div class="x-body">
    <form class="layui-form" method="POST" action="{:url('edit')}" id="from_id">
        <!--地区名称-->
        <div class="layui-form-item">
            <label for="region_name" class="layui-form-label">
                <span class="x-red">*</span>地区名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="region_name" name="region_name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="{$region_info.region_name}">
            </div>
        </div>

        <!--排序-->
        <div class="layui-form-item">
            <label for="L_sort_order" class="layui-form-label">
                排序
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_sort_order" name="sort_order" lay-verify="m_sort_order"
                       autocomplete="off" class="layui-input" value="{$region_info.sort_order}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">0-255</span>
            </div>
        </div>

        <!--首字母-->
        <div class="layui-form-item">
            <label for="L_first_char" class="layui-form-label">
                首字母
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_first_char" name="first_char" lay-verify="m_first_char"
                       autocomplete="off" class="layui-input" value="{$region_info.first_char}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">请填写小写的首字母</span>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="region_id" value="{$region_info.region_id}">
                <button  class="layui-btn" lay-filter="edit" lay-submit="">
                    修改
                </button>
            </div>
        </div>
    </form>
</div>

{/block}

{block name="script"}
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
                ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            m_sort_order:function (value) {
                if (value != "") {
                    value = parseInt(value);
                    //验证是否是 0-255
                    var emReg = /^\d{1,3}$/;
                    if(!emReg.test(value) || value < 0 || value > 255) {
                        return "只能填写0-255区间的数字!";
                    }
                }
            },
            m_first_char:function (value) {
                if (value != "") {
                    //验证是否是字母
                    var emReg = /^[a-zA-Z]$/;
                    if(!emReg.test(value)) {
                        return "只能填写字母!";
                    }
                } else {
                    return "请填写首字母!";
                }
            }
        });

        //监听提交
        form.on('submit(edit)', function(data){
            $("#from_id").ajaxSubmit({
                beforeSubmit:function () {
                },
                success:function (data) {
                    //console.log(JSON.stringify(data));
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:5,time:1500});
                    } else {
                        layer.alert("修改成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新父层页面
                            parent.location.replace(parent.location.href);
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
{/block}